﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using Skugo.Core;

namespace Skugo.Driver
{
	public partial class Main : Form
	{
		Client mClient;
		PacketRouter mPacketRouter;

		public Main()
		{
			mClient = new Client();
			mPacketRouter = new PacketRouter(mClient);

			mClient.Connected += Connected;
			mClient.ConnectionFailed += ConnectionFailed;
			mClient.Disconnected += Disconnected;

			InitializeComponent();
		}

		private void Main_Load(object sender, EventArgs e)
		{
			// Give access to core elements (such as the window/dock)
			FrameworkWindow.Main = this;
			FrameworkWindow.Dock = this.DockPanel;

			mClient.Connect("127.0.0.1", 8000);

			//MemoryStream ms = new MemoryStream();
			//BinaryWriter writer = new BinaryWriter(ms);

			//writer.Write((uint)10);
			//writer.Write((ulong)55);
			//writer.Write((byte)'a');
			//writer.Write((byte)'b');
			//writer.Write((byte)'c');
			//writer.Write((byte)'d');
			//writer.Write((byte)'1');
			//writer.Write((byte)'2');
			//writer.Write((byte)'3');
			//writer.Write((byte)'4');
			//writer.Write((byte)'!');
			//writer.Write((byte)'Z');

			//client.Client.Send(ms.ToArray());
		}

		void Disconnected(Client client)
		{
			this.Text = "Disconnected";
		}

        void ConnectionFailed(Client client)
		{
			this.Text = "ConnectionFailed";
		}

        void Connected(Client client)
		{
			this.Text = "Connected";
		}

		private void ClientPump_Tick(object sender, EventArgs e)
		{
			mClient.Update();
		}
	}
}
